<template>
  <div id="scroll-board">
    <dv-scroll-board :config="config" />
  </div>
</template>

<script>
export default {
  name: "ScrollBoard",
  props: ["data"],
  data() {
    return {
      config: {
        header: ["时间", "内容", "情绪", "备注"],
        data: this.data,
        index: true,
        columnWidth: [50, 200, 400, 100],
        align: ["center"],
        rowNum: 7,
        headerBGC: "#1981f6",
        headerHeight: 45,
        oddRowBGC: "rgba(0, 44, 81, 0.8)",
        evenRowBGC: "rgba(10, 29, 50, 0.8)",
      },
    };
  },
  methods: {
    createData() {
      let data = this.config.data.slice();
      const { config } = this;
      data.reverse();
      this.config.data = data;
      config;
      this.config = { ...this.config };
    },
    updateData(row) {
      let data = this.config.data.slice();
      while(data.length>=20)
      {
        data.pop();
      }
      const { config } = this;
      data.unshift([this.formatDateS(row.create_time),row.content,row.label2,row.remark]);
      this.config.data = data;
      config;
      this.config = { ...this.config };
    },
    formatDateS(UTCDateString) {
      if (!UTCDateString) {
        return "-";
      }
      function formatFunc(str) {
        //格式化显示
        return str > 9 ? str : "0" + str;
      }
      var date2 = new Date(UTCDateString); //这步是关键
      var year = date2.getFullYear();
      var mon = formatFunc(date2.getMonth() + 1);
      var day = formatFunc(date2.getDate());
      var hour = formatFunc(date2.getHours());
      var minute = formatFunc(date2.getMinutes());
      var second = formatFunc(date2.getSeconds());
      var dateStr =
        year + "-" + mon + "-" + day + " " + hour + ":" + minute + ":" + second;
      return dateStr;
    },
  },
  mounted() {
    this.createData();
  },
};
</script>

<style lang="less">
#scroll-board {
  width: 50%;
  box-sizing: border-box;
  margin-left: 20px;
  height: 100%;
  overflow: hidden;
}
</style>
